function containerCode(cache) {
  const { radius, fills, borders, points, top, left, type, height, width, id, opacity } = cache.data;
  console.log("containerCode id: " + id);

  let flutterCode = `Container(
      width: ${unit(width)},
      height: ${unit(height)},
      alignment: Alignment.center,
    `;

  if (type === 'shape') {

    let decoration = [];
    if (radius) {
      let borderRadius = borderRadiusCode(radius);
      decoration.push(`borderRadius: ${borderRadius}`);
    }

    if (fills && fills.length > 0) {
      const { gradient, color } = fills[fills.length - 1];
      if (gradient) {
        const { colorStops } = gradient;
        const colors = colorStops.map(({ color }) => `${rgbaToHex(color.value, opacity / 100)}`).join(', ');
        const begin = gradient.from;
        const end = gradient.to;

        decoration.push(`gradient: LinearGradient(
            begin: Alignment(${num(begin.x)}, ${num(begin.y)}),
            end: Alignment(${num(end.x)}, ${num(end.y)}),
            colors: [${colors}],
          )`);
      } else if (color) {
        decoration.push(`color: ${rgbaToHex(color.value, opacity / 100)}`);
      }
    }

    if (borders && borders.length > 0) {
      const border = borders[0];
      if (border.type === 'color') {
        decoration.push(`border: Border.all(color: ${rgbaToHex(border.color.value, opacity / 100)}, width: ${unit(border.thickness)})`);
      }
    }

    if (decoration.length > 0) {
      flutterCode += `
          decoration: BoxDecoration(
            ${decoration.join(',\n')}
          ),
          `;
    }
  }

  if (cache.children && cache.children.length > 0) {
    cache.children.sort((a, b) => {
      return a.index - b.index
    });
    for (let i = 0; i < cache.children.length; i++) {
      let child = cache.children[i];

      let padding = edgeInsetsCode(cache.data, child.data);
      if (padding.length > 0) {
        flutterCode += `
          padding: ${padding},
      `;
      }

      let childCode = doExport(child);
      if (childCode.length > 0) {
        flutterCode += `
        child: ${childCode},
      `;
      }
    }

  }

  flutterCode += `
    )`;

  return flutterCode;
}

function borderRadiusCode(radius) {
  let borderRadius;

  if (radius.length === 1) {
    borderRadius = `BorderRadius.circular(${unit(radius[0])})`;
  } else if (sameRadius(radius)) {
    borderRadius = `BorderRadius.circular(${unit(radius[0])})`;
  } else {
    const filteredRadius = radius.filter(r => r !== 0);
    const borderRadiusProperties = [];

    if (directionalSupport) {
      if (radius[0] !== 0) {
        borderRadiusProperties.push(`topStart: Radius.circular(${unit(radius[0])})`);
      }
      if (radius[1] !== 0) {
        borderRadiusProperties.push(`topEnd: Radius.circular(${unit(radius[1])})`);
      }
      if (radius[2] !== 0) {
        borderRadiusProperties.push(`bottomEnd: Radius.circular(${unit(radius[2])})`);
      }
      if (radius[3] !== 0) {
        borderRadiusProperties.push(`bottomStart: Radius.circular(${unit(radius[3])})`);
      }

      borderRadius = `BorderRadiusDirectional.only(\n${borderRadiusProperties.join(', \n')})`;
    } else {
      if (radius[0] !== 0) {
        borderRadiusProperties.push(`topLeft: Radius.circular(${unit(radius[0])})`);
      }
      if (radius[1] !== 0) {
        borderRadiusProperties.push(`topRight: Radius.circular(${unit(radius[1])})`);
      }
      if (radius[2] !== 0) {
        borderRadiusProperties.push(`bottomRight: Radius.circular(${unit(radius[2])})`);
      }
      if (radius[3] !== 0) {
        borderRadiusProperties.push(`bottomLeft: Radius.circular(${unit(radius[3])})`);
      }

      borderRadius = `BorderRadius.only(\n${borderRadiusProperties.join(', \n')})`;
    }
  }
  return borderRadius;
}

function sameRadius(radius) {
  return radius.every((r) => r === radius[0]);
}

function getContainerColor(data) {
  if (data.fills && data.fills.length > 0) {
    let fill = data.fills[data.fills.length - 1];

    if (fill.color) {
      return rgbaToHex(fill.color.value, data.opacity / 100);
    }
  }

  return '';
}